/*
Copyright (c) 2006 - 2008  Universitaet Osnabrueck, virtUOS
Authors: Markus Ketterl, Johannes Emden, Nils Schuhmacher, Andreas Rickling

This file is part of virtPresenter.

virtPresenter is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

virtPresenter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with virtPresenter.  If not, see <http://www.gnu.org/licenses/>.
*/

package virtPresenter.model
{
	import mx.collections.ArrayCollection;
	
	/**
	 * Class TreeListItem creates the tree items for the search result.
	 * */
	public class TreeListItem
	{
		private var _slideID:int=0;
		private var _appointment:String=""; //folder
		private var _time:int=0;
		private var _label:String="";		
		private var children:ArrayCollection = new ArrayCollection();
		
		/**
		 * Setter for slideID.
		 * */
		public function set slideID(slideID:int):void
		{
			_slideID=slideID;
		}
		
		/**
		 * Getter for slideID.
		 * */
		public function getID():int
		{
			return _slideID;
		}
		
		/**
		 * Setter for the appointment (lecturefolder).
		 * */
		public function set appointment(appointment:String):void
		{
			_appointment=appointment;
		}
		
		/**
		 * Getter for the appointment (lecturefolder).
		 * */
		public function get appointment():String
		{
			return _appointment;
		}
		
		/**
		 * Setter for the label.
		 * */
		public function set label(label:String):void
		{
			_label=label;
		}
		
		/**
		 * Getter for the label.
		 * */
		public function get label():String
		{
			return _label;
		}		
		
		/**
		 * Setter for the time.
		 * */		
		public function set time(time:int):void
		{
			_time=time;
		}		
		
		/**
		 * Getter method for the length of the children array.
		 * */
		public function get size():int
		{
			return children.length;
		}
		
		/**
		 * Adds a TreeListItem entry to the children array. 
		 * */
		public function addChild(child:TreeListItem):void
		{
			children.addItem(child);
		}
		
		/**
		 * Delivers the String representation of the TreeListItem.
		 * */
		public function toString():String
		{				
			var result:String="";
		
			if(children.length==0)
			{
				result="<item "+
						"appointment='"+_appointment+"' "+
						"time='"+_time+"' "+
						"label='"+_label+"'/>";
			}
			else if(children.length==1 && _slideID!=0)
			{
				result="<item "+
						"appointment='"+_appointment+"' "+
						"time='"+_time+"' "+
						"label='Folie "+_slideID+": "+TreeListItem(children[0]).label+"'/>";	
			}
			else{
				result=
				"<item "+
						"appointment='"+_appointment+"' "+
						"time='"+_time+"' "+
						"label='"+_label+"'>";	
					
				for(var i:int;i<children.length;i++)
				{
					result = result+children[i].toString();
				}		
		
				result = result+
			    		"</item>";
			}			
			
			return result;
		}		
		
	}
}